package com.agriculture.data_demo.repository;

import com.agriculture.data_demo.entity.sys.HenDailyEntity;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

/**
 * @author morningbear
 * @date 20.10.8
 */
@Repository
public interface HenDailyRepository extends JpaRepository<HenDailyEntity, Integer> {

    @Query(value = "select * from hen_daily", nativeQuery = true)
    Page<HenDailyEntity> findAll(PageRequest of);

    /**
     *
     * @param shed 鸡舍
     * @return 根据鸡舍名称查找
     */
    @Query(value = "select * from hen_daily where shedName = ?1", nativeQuery = true)
    Page<HenDailyEntity> findByShed(String shed, PageRequest of);

    /**
     *
     * @return prodRate大于平均的鸡舍
     */
    @Query(value = "select  * from hen_daily where prodRate > (select avg(prodRate) from hen_daily)", nativeQuery = true)
    Page<HenDailyEntity> findByProdRate(PageRequest of);
}
